// mobile bind
// ============

define(['zepto', 'sui', 'submitForm'], function($){
  return {
    init: function(data) {
      this.couldEdit = data.couldEdit;
      
      // TODO add validate here
      this.submit();
    },
    
    submit : function() {
      var that = this;
      $("form").submitform({
        beforeSubmit : function(el) {
          if(that.couldEdit === 'true') {
            var bust = $('input[name="bust"]').val().trim();
            var waist = $('input[name="waist"]').val().trim();
            var hips = $('input[name="hips"]').val().trim();
            var expression = /^[0-9]+([.]{1}[0-9]+){0,1}$/;
            if(!bust || !waist || !hips) {
              $.toast("三围数据不可为空");
              return false;
            } else if(!expression.test(bust) || !expression.test(waist) || !expression.test(hips)) {
              $.toast("请输入正确的三围数据")
              return false;
            }
            return true;
          } else {
            return true;
          }
        },
        successUrl: __CTX__.root + "/signin-success",
        failureUrl: __CTX__.root + "/signin-error?message=签到失败"
      })
    }
  }
})

